<template>
	<view class="change-password">
		<u-top-tips ref="uTips"></u-top-tips>
		<u-form :model="form" ref="uForm" label-width="200">
			<u-form-item label="旧密码">
				<u-input v-model="form.oPwd" />
			</u-form-item>
			<u-form-item label="新密码">
				<u-input v-model="form.nPwd" />
			</u-form-item>
			<u-form-item label="确认密码">
				<u-input v-model="form.rnPwd" />
			</u-form-item>
		</u-form>
		<view class="button-box">
			<button class="cu-btn bg-blue" @click="changePwd">立即修改</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					oPwd: "", //旧密码
					nPwd: "", //新密码
					rnPwd: '', //确认新密码
				}
			};
		},
		computed: {
			loginUser() {
				return uni.getStorageSync('login_user_info')
			}
		},
		methods: {
			async changePwd() {
				let result = ''
				if (this.form.oPwd) {
					if (this.form.nPwd) {
						if (this.form.nPwd !== this.form.rnPwd) {
							result = '两次输入密码不一致,请检查'
						}
					} else {
						result = '请输入新密码'
					}
				} else {
					result = '请输入旧密码'
				}
				if (result) {
					this.$refs.uTips.show({
						title: result,
						type: 'warning',
						duration: '2300'
					})
					return
				}

				let req = [{
					"serviceName": "srvsso_user_pwd_reset",
					"data": [{
						"pwd": this.form.oPwd,
						"newpwd": this.form.nPwd
					}]
				}]
				let res = await this.onRequest("operate", "srvsso_user_pwd_reset", req, "sso")
				if (res.data.state === 'SUCCESS') {
					uni.showModal({
						title: '修改成功',
						content: '即将跳转到登录页面',
						showCancel: false,
						success(res) {
							if (res.confirm) {
								uni.reLaunch({
									url: `/pages/public/accountExec/accountExec?user_no=${this.loginUser?.user_no}&pwd=${this.form.nPwd}`
								})
							}
						}
					})
				} else {
					// uni.showToast({
					// 	title:res.data.resultMessage,
					// 	icon:'none'
					// })
					this.$refs.uTips.show({
						title: res.data.resultMessage,
						type: 'warning',
						duration: '2300'
					})
				}

			}
		},
	}
</script>

<style lang="scss" scoped>
	.change-password {
		padding: 20rpx;
		// height: calc(100vh - var(--window-top));
		background-color: #FFFFFF;
		width: 90%;
		margin: 20rpx auto;
		.u-form-item{
			border-bottom: 1px solid #F5F6FA;
		}
		.button-box {
			text-align: center;
			padding: 20rpx 0 40rpx;
		}
	}
</style>
